package com.example.config;

import com.example.interceptors.LoginInterceptors;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {

    // 白名单
    private static final List<String> BYPASS_PATHS = List.of(
            "/user/login", "/user/register"
    );

    private final LoginInterceptors loginInterceptors;

    /**
     * 配置拦截器
     *
     * @param registry 相当于拦截器的注册中心
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录接口和注册接口不拦截
        registry.addInterceptor(this.loginInterceptors)
                .excludePathPatterns(BYPASS_PATHS); //  登录和注册接口放行
    }
}
